package comm;

import java.util.ArrayList;

import env.PushableObj;

/**
 * Central controller for robot decision-making.
 */
public class Whiteboard {
	// The list of tasks
	public static ArrayList<TaskNode> tasks = new ArrayList<TaskNode>();

	// The list of seen or known pushable objects
	public static ArrayList<PushableObj> seenObjs = new ArrayList<PushableObj>();

	// The list of objects undergoing auctions
	public static ArrayList<PushableObj> unavailObjs = new ArrayList<PushableObj>();

	public static double priorityOf(PushableObj o) {
		for (TaskNode t : tasks)
			if (t.task.equals(o))
				return t.priority;
		return 0;
	}

	// Called when pushable object reaches goal. It is not "seen" anymore.
	public static void complete(PushableObj o) {
		seenObjs.remove(o);
		for (TaskNode t : tasks)
			if (t.task.equals(o)) {
				t.complete();
				return;
			}
	}

	public static void objSeen(PushableObj o) {
		if (!seenObjs.contains(o))
			//System.out.println("ObjSeen: "+o);
			seenObjs.add(o);
	}

	// Removes object from consideration.
	public static void objTake(PushableObj o) {
		seenObjs.remove(o);
		objUnavail(o);
	}

	// Called when object will be auctioned.
	public static void objUnavail(PushableObj o) {
		if (!unavailObjs.contains(o))
			unavailObjs.add(o);
	}

	// Called when object is finished being auctioned.
	public static void objAvail(PushableObj o) {
		unavailObjs.remove(o);
	}

	public static boolean isAvail(PushableObj o) {
		return !unavailObjs.contains(o);
	}
}
